package com.valley.dream.birds.common.util;

import lombok.Data;

/**
 * @author Valley
 * Created by Valley on 2022/7/6
 */

@Data
public class Result<T> {

    public static final Integer SUCCESS_CODE = 200;
    public static final String SUCCESS_MSG = "请求成功";

    public static final Integer FAIL_CODE = 444;
    public static final String FAIL_MSG = "请求失败";

    private Integer code;

    private String msg;

    private T data;

    public static <T> Result ok(T t){
        Result<T> result = new Result<>();
        result.setData(t);
        result.setCode(SUCCESS_CODE);
        result.setMsg(SUCCESS_MSG);
        return result;
    }

    public static Result ok(){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setMsg(SUCCESS_MSG);
        return result;
    }

    public static Result fail(){
        Result result = new Result();
        result.setCode(FAIL_CODE);
        result.setMsg(FAIL_MSG);
        return result;
    }

}
